//
//  ViewController.m
//  05-隐式动画
//
//  Created by J on 16/2/23.
//  Copyright © 2016年 J. All rights reserved.
//

#define  angleRamdom(angle)  ((angle)/180.0*M_PI)

#define  randamAngle(angle) ((angle)/)
#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,weak)CALayer* layer;
@property (weak, nonatomic) IBOutlet UIView *grayView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CALayer* layer= [CALayer layer];
    layer.position = CGPointMake(100, 200);//position默认0,0
//    layer.anchorPoint = CGPointZero;//默认0.5,0.5 控件的中心点 宽度一半 高度一半 所以默认显示1/4 设置为0,0显示所有的
    layer.bounds = CGRectMake(0, 0, 50, 50);

    layer.backgroundColor = [UIColor orangeColor].CGColor;
    _layer = layer;
    [self.view.layer addSublayer:layer];
    
    
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //旋转操作
//    [UIView animateWithDuration:1.0 animations:^{
        _layer.transform = CATransform3DMakeRotation(angleRamdom(arc4random_uniform(360)+1), 0, 0, 1);//默认就有动画效果  自己加一个 animateWithDuration无效
    _layer.position = CGPointMake(arc4random_uniform(300), arc4random_uniform(300));
    _layer.cornerRadius = arc4random_uniform(50);
    _layer.backgroundColor = [self randomColor].CGColor;
    _layer.borderWidth = arc4random_uniform(10);
    _layer.borderColor = [self randomColor].CGColor;
    

//    }];
    

    
    //_grayView自带的layer为系统自己创建的没有隐式动画
//        [UIView animateWithDuration:1.0 animations:^{//需要自己加一个动画效果
//
//    _grayView.layer.transform = CATransform3DMakeRotation(angleRamdom(arc4random_uniform(360)+1), 0, 0, 1);//默认就有动画效果
//    _grayView.layer.position = CGPointMake(arc4random_uniform(300), arc4random_uniform(300));
//    _grayView.layer.cornerRadius = arc4random_uniform(50);
//    _grayView.layer.backgroundColor = [self randomColor].CGColor;
//    _grayView.layer.borderWidth = arc4random_uniform(10);
//    _grayView.layer.borderColor = [self randomColor].CGColor;
//    
//        }];
    
}

- (UIColor*)randomColor{
    
    CGFloat r = arc4random_uniform(256)/255.0;
    CGFloat g = arc4random_uniform(256)/255.0;
    CGFloat b = arc4random_uniform(256)/255.0;

    
    return [UIColor colorWithRed:r green:g blue:b alpha:1.0];
}

@end
